#include "mii.h"
#include "wiimote.h"
#include "wiimote_error.h"
#include "wiimote_io.h"
#include <stdio.h>
#include <stdlib.h>


//------------------------------------------------------------------------------
//  Function:   Util_SaveData::ReadAllToFile
//  Purpose:    Read all save data to the given file
//  Parameters:
//  Returns:
//------------------------------------------------------------------------------
int wiimote_read_to_file(wiimote_t *wiimote, const char* filename)
// int wiimote_read_to_file(wiimote_t *wiimote)
{
// int wiimote_read(wiimote_t *wiimote, uint32_t addr, uint8_t *data, uint16_t size)

        uint8_t data[WIIMOTE_SAVEDATA_SIZE];
        if (wiimote_read(wiimote, WIIMOTE_SAVEDATA_BEGIN, data, WIIMOTE_SAVEDATA_SIZE) ) {
                return WIIMOTE_ERROR;
        }


      FILE *file;
      file = fopen(filename,"a+");
      //file = fopen("file.txt","a+");
      fwrite(data, sizeof(data[0]), sizeof(data)/sizeof(data[0]), file);
      fclose(file);

      return 1;
}
